package com.zhang.service.Impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.domain.Department;
import com.zhang.domain.LoginInfo;
import com.zhang.domain.Manager;
import com.zhang.domain.Shop;
import com.zhang.mapper.EmployeeMapper;
import com.zhang.query.EmployeeQuery;
import com.zhang.service.IEmpService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zh
 * @create 2022-02-15 16:00
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmpServiceImpl implements IEmpService {
    @Resource
    private EmployeeMapper mapper;
    @Transactional
    @Override
    public void update(Manager m) {
        mapper.update(m);
    }
    @Transactional
    @Override
    public void add(Manager m) {
        mapper.add(m);
    }
    @Transactional
    @Override
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public List<Manager> selectAll() {
        return mapper.loadAll();
    }

    @Override
    public PageInfo<Manager> selectData(EmployeeQuery query) {
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<Manager> managers = mapper.queryData(query);
        Page<Manager> page = (Page<Manager>) managers;
        return page.toPageInfo();
    }
    @Transactional
    @Override
    public void deleteAll(Long[] id) {
        mapper.deleteAll(id);
    }

    @Override
    public List<Department> selAllDept() {
        return mapper.selAllDept();
    }

    @Override
    public List<LoginInfo> selAllLoginInfo() {
        return mapper.selAllLoginInfo();
    }

    @Override
    public List<Shop> selAllShop() {
        return mapper.selAllShop();
    }
}
